//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.example.administrator.myjdlc.db;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.administrator.myjdlc.AppApplication;


public class DBUtils {
    private static DBUtils util = null;
    private static DBInitHelper helper = null;
    private static DBBack dBBack;
    private DBInterface listener;

    public DBUtils() {
    }

    public static DBUtils getInstance() {
        if(util == null) {
            util = new DBUtils();
        }

        dBBack = new DBBack();
        return util;
    }

    public void createDataBase(String dbName, String tableName, int dbVersion, String createTableSql, DBInterface dBInterface) {
        this.listener = dBInterface;

        try {
            DBInitHelper.setDbName(dbName);
            DBInitHelper.setTableName(tableName);
            DBInitHelper.setDbVersion(dbVersion);
            DBInitHelper.setCreateTableSql(createTableSql);
            if(helper == null) {
                helper = new DBInitHelper(AppApplication.getContext());
            }

            dBBack.setCode(0);
            dBBack.setEventCode(1);
        } catch (Exception var7) {
            dBBack.setCode(1);
            dBBack.setEventCode(1);
            dBBack.setErrorMessage(var7.getMessage());
        }

        if(this.listener != null) {
            this.listener.dBListener(dBBack);
        }

    }

    public void addData(String tableName, ContentValues value, DBInterface dBInterface) {
        this.listener = dBInterface;

        try {
            if(helper == null) {
                helper = new DBInitHelper(AppApplication.getContext());
            }

            SQLiteDatabase e = helper.getWritableDatabase();
            long id = e.insert(tableName, (String)null, value);
            e.close();
            dBBack.setCode(0);
            dBBack.setEventCode(2);
            dBBack.setObj(Long.valueOf(id));
        } catch (Exception var7) {
            dBBack.setCode(1);
            dBBack.setEventCode(2);
            dBBack.setErrorMessage(var7.getMessage());
        }

        if(this.listener != null) {
            this.listener.dBListener(dBBack);
        }

    }

    public void deleteData(String tableName, String where, String[] whereArgs, DBInterface dBInterface) {
        this.listener = dBInterface;

        try {
            if(helper == null) {
                helper = new DBInitHelper(AppApplication.getContext());
            }

            SQLiteDatabase e = helper.getWritableDatabase();
            e.delete(tableName, where, whereArgs);
            e.close();
            dBBack.setCode(0);
            dBBack.setEventCode(3);
        } catch (Exception var6) {
            dBBack.setCode(1);
            dBBack.setEventCode(3);
            dBBack.setErrorMessage(var6.getMessage());
        }

        if(this.listener != null) {
            this.listener.dBListener(dBBack);
        }

    }

    public void updateData(String tableName, ContentValues values, String where, String[] whereArgs, DBInterface dBInterface) {
        this.listener = dBInterface;

        try {
            if(helper == null) {
                helper = new DBInitHelper(AppApplication.getContext());
            }

            SQLiteDatabase e = helper.getWritableDatabase();
            e.update(tableName, values, where, whereArgs);
            e.close();
        } catch (Exception var7) {
            dBBack.setCode(1);
            dBBack.setEventCode(3);
            dBBack.setErrorMessage(var7.getMessage());
        }

        if(this.listener != null) {
            this.listener.dBListener(dBBack);
        }

    }

    public void queryData(String tableName, String where, String[] whereArgs, String orderBy, String limit, DBInterface dBInterface) {
        this.listener = dBInterface;

        try {
            if(helper == null) {
                helper = new DBInitHelper(AppApplication.getContext());
            }

            SQLiteDatabase e = helper.getWritableDatabase();
            Cursor c = null;
            c = e.query(tableName, (String[])null, where, whereArgs, (String)null, (String)null, orderBy, limit);
            dBBack.setCode(0);
            dBBack.setEventCode(5);
            dBBack.setObj(c);
        } catch (Exception var9) {
            dBBack.setCode(1);
            dBBack.setEventCode(5);
            dBBack.setErrorMessage(var9.getMessage());
        }

        if(this.listener != null) {
            this.listener.dBListener(dBBack);
        }

    }
}
